package pATT.profilingAlgorithm.PersonalSearcher;
/***************************************************************************
 *                              AbstractDocument                           * 
 *                       initial version by: Travis Bauer                  *
 *                      copyright (C) 2000 IGLU Research Group             *
 *                             trbauer@indiana.edu                         *
 ***************************************************************************/
/***************************************************************************
 * The licence for this code is included in LICENSE.txt.  If you did not   *
 * get this file with this distribution, request a copy from               *
 * iglu@cs.indiana.edu                                                     *
 ***************************************************************************/

import java.util.StringTokenizer;
import java.util.Iterator;
import java.io.Serializable;

public abstract class AbstractDocument implements Document, Serializable {

	private String fullContent=null;
	private String indexibleContent=null;
//	private String language=null;


  /** Contains a list of words occurring and how often they occur */
  private TermVector tv = null;
  private int size = 0;

  public abstract String getStylizedText(int style);

  public String getFullContent() {
    return fullContent;
  }

  public String getIndexibleContent() {
    return indexibleContent;
  }

  public void setIndexibleContent(String content) {
    indexibleContent=content;
    tv=null;
  }

  public void setFullContent(String content) {
    fullContent=content;
  }

  public int numOccurs(String w) {
    if (tv==null) loadTermVector();
    return (int)tv.get(w);
  }

  public int numWords() {
    if (tv==null) loadTermVector();
    return size;
  }

  public int numUniqueWords() {
    if (tv==null) loadTermVector();
    return tv.size();
  }

  private void loadTermVector() {
    tv = new TermVector();
    for (StringTokenizer st = new StringTokenizer(getIndexibleContent());
	 st.hasMoreTokens(); ) {
      String s = st.nextToken();
      tv.put(s, 1.0+tv.get(s));
    }

    //calculate document size
    for (Iterator i = tv.termIterator(); i.hasNext(); ) {
      size+=(int)tv.get(i.next().toString());
    }  
  }

  public String toString() {
    return getFullContent();
  }
}


